<style>
    .layout{
        border: 1px solid #d7dde4;
        background: #f5f7f9;
        position: relative;
        border-radius: 4px;
        overflow: hidden;
    }
    .layout-breadcrumb{
        padding: 10px 15px 0;
    }
    .layout-content{
        min-height: 200px;
        margin: 15px;
        overflow: hidden;
        background: #fff;
        border-radius: 4px;
    }
    .layout-content-main{
        padding: 10px;
    }
    .layout-copy{
        text-align: center;
        padding: 10px 0 20px;
        color: #9ea7b4;
    }
    .layout-menu-left{
        background: #464c5b;
    }
    .layout-header{
        height: 60px;
        background: #fff;
        box-shadow: 0 1px 1px rgba(0,0,0,.1);
    }
    .layout-header-menu{
        height: 60px;
        box-shadow: 0 1px 1px rgba(0,0,0,.1);
    }
    .layout-logo-left{
        width: 90%;
        height: 30px;
        background: #5b6270;
        border-radius: 3px;
        margin: 15px auto;
    }
    .layout-ceiling-main a{
        color: #9ba7b5;
    }
    .layout-hide-text .layout-text{
        display: none;
    }
    .ivu-col{
        transition: width .2s ease-in-out;
    }
</style>
<template>
    <div class="layout">
        <div style="position:fixed;width:100%;z-index:4">
            <Menu mode="horizontal" :theme="theme1" active-name="1">
                <Menu-item name="2">
                    <Icon type="ios-people"></Icon>
                    用户管理
                </Menu-item>
                <Submenu name="3">
                    <template slot="title">
                        <Icon type="stats-bars"></Icon>
                        统计分析
                    </template>
                    <Menu-group title="使用">
                        <Menu-item name="3-1">新增和启动</Menu-item>
                        <Menu-item name="3-2">活跃分析</Menu-item>
                        <Menu-item name="3-3">时段分析</Menu-item>
                    </Menu-group>
                    <Menu-group title="留存">
                        <Menu-item name="3-4">用户留存</Menu-item>
                        <Menu-item name="3-5">流失用户</Menu-item>
                    </Menu-group>
                </Submenu>
                <!-- <Menu-item name="4">
                    <Icon type="settings"></Icon>
                    综合设置
                </Menu-item>
                <Menu-item name="leftMenuToggle" v-if="">
                    <div class="layout-header-menu">
                        <i-button type="text" @click="toggleClick">
                            <Icon type="navicon" size="32"></Icon>
                        </i-button>
                    </div>
                </Menu-item> -->
            </Menu>
        </div>
        <div>
            <div class="leftMenu layout-menu-left" v-bind:style="{display:showMenu,height:(screenHeight-58)+'px'}" style="position:fixed;z-index:3;float:left;left:0px;top:60px;overflow-y:auto">
                <Menu  :theme="theme2" :open-names="['1']" accordion>
                    <Submenu name="1">
                        <template slot="title">
                            <Icon type="ios-paper"></Icon>
                            表单样例
                        </template>
                        <Menu-item name="1-1" @click.native="goto('/Admin/GentForm')" href="/Admin/GentForm">常规表单</Menu-item>
                        <Menu-item name="1-2" @click.native="goto('/Admin/ValidForm')" href="/Admin/ValidForm">校验表单</Menu-item>
                        <Menu-item name="1-3">举报管理</Menu-item>
                    </Submenu>
                    <Submenu name="2">
                        <template slot="title">
                            <Icon type="ios-people"></Icon>
                            用户管理
                        </template>
                        <Menu-item name="2-1">新增用户</Menu-item>
                        <Menu-item name="2-2">活跃用户</Menu-item>
                    </Submenu>
                    <Submenu name="3">
                        <template slot="title">
                            <Icon type="stats-bars"></Icon>
                            统计分析
                        </template>
                        <Menu-group title="使用">
                            <Menu-item name="3-1">新增和启动</Menu-item>
                            <Menu-item name="3-2">活跃分析</Menu-item>
                            <Menu-item name="3-3">时段分析</Menu-item>
                        </Menu-group>
                        <Menu-group title="留存">
                            <Menu-item name="3-4">用户留存</Menu-item>
                            <Menu-item name="3-5">流失用户</Menu-item>
                        </Menu-group>
                    </Submenu>
                </Menu>
            </div>
            <div class="rightDock" v-bind:style="{'padding-left':paddingLeft}" style="background-color:white;padding-top:60px">
                <div class="layout-header">
                    <i-button type="text" @click="toggleClick">
                        <Icon type="navicon" size="32"></Icon>
                    </i-button>
                </div>
                <div class="layout-breadcrumb">
                    <Breadcrumb>
                        <Breadcrumb-item href="#">{{route_title}}</Breadcrumb-item>
                    </Breadcrumb>
                </div>
                <div class="layout-content">
                    <div class="layout-content-main">
                        <router-view></router-view>
                    </div>
                </div>
                <div class="layout-copy">
                    2011-2016 &copy; TalkingData
                </div>
            </div>
            <div class="clear:both"></div>
        </div>
    </div>
</template>
<script>
    import Routers from './router';
    export default {
        data () {
            return {
                theme1:'light',
                theme2: 'dark',
                showMenuToggle:true,
                leftMenuStyle:{},
                route_title:"",
                screenWidth: document.body.clientWidth,
                screenHeight: document.documentElement.clientHeight
            }
        },
        mounted() {
            this.$router.afterEach(route => {
                this.route_title=route.meta.title;
            });
            const that = this;
            window.onresize = () => {
                return (() => {
                    window.screenWidth = document.body.clientWidth;
                    that.screenWidth = window.screenWidth;
                    window.screenHeight = document.documentElement.clientHeight;
                    that.screenHeight = window.screenHeight;
                })();
            }
        },
        computed: {
            iconSize () {
                return this.spanLeft === 24;
            },
            showMenu(){
                if(this.showMenuToggle)
                {
                    return "block";
                }else{
                    return "none";
                }
            },
            paddingLeft(){
                if(this.showMenuToggle)
                {
                    return "240px";
                }else{
                    return "0px";
                }
            }
        },
        watch:{
            screenWidth (val) {
                if (!this.timer) {
                    this.screenWidth = val
                    this.timer = true
                    let that = this
                    setTimeout(function () {
                        // that.screenWidth = that.$store.state.canvasWidth
                        if(that.screenWidth>768)
                        {
                            that.showMenuToggle=true;
                        }else{
                            that.showMenuToggle=false;
                        }
                        that.timer = false
                    }, 400)
                }
            }
        },
        methods: {
            toggleClick () {
                if (this.showMenuToggle) {
                    this.showMenuToggle=false;
                } else {
                    this.showMenuToggle=true;
                }
            },
            goto(url){
                this.$router.push(url);
            }
        }
    }
</script>